Amazon AuroraのJDBCメタデータとサポート状況を確認した
Auroraの各種メタデータを取得する
Auroraリリースおめでとうございます!ということで、様々なメディアで取り上げられていると思いますが、プログラマーにとってどんなものか把握するために、各種メタデータやサポート状況をプログラムから取得したいと思います。トランザクションの分離レベルとか、セーブポイントとか、ユニオンとかとか、知りたいですよね?
import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; public class AuroraMetaData { public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://cm1-cluster.cluster-XXXX.us-west-2.rds.amazonaws.com:3306/?user=XXXX&password=XXXX"; Connection conn = DriverManager.getConnection(url); DatabaseMetaData dbmd = conn.getMetaData(); System.out.println("※※※※※ METADATA ※※※※※"); System.out.println("getCatalogSeparator : " + dbmd.getCatalogSeparator()); System.out.println("getCatalogTerm : " + dbmd.getCatalogTerm()); System.out.println("getDatabaseProductName : " + dbmd.getDatabaseProductName()); System.out.println("getDatabaseProductVersion : " + dbmd.getDatabaseProductVersion()); System.out.println("getDatabaseMajorVersion : " + dbmd.getDatabaseMajorVersion()); System.out.println("getDatabaseMinorVersion : " + dbmd.getDatabaseMinorVersion()); System.out.println("getDefaultTransactionIsolation : " + dbmd.getDefaultTransactionIsolation()); System.out.println("getDriverMajorVersion : " + dbmd.getDriverMajorVersion()); System.out.println("getDriverMinorVersion : " + dbmd.getDriverMinorVersion()); System.out.println("getDriverName : " + dbmd.getDriverName()); System.out.println("getDriverVersion : " + dbmd.getDriverVersion()); System.out.println("getExtraNameCharacters : " + dbmd.getExtraNameCharacters()); System.out.println("getIdentifierQuoteString : " + dbmd.getIdentifierQuoteString()); System.out.println("getJDBCMajorVersion : " + dbmd.getJDBCMajorVersion()); System.out.println("getJDBCMinorVersion : " + dbmd.getJDBCMinorVersion()); System.out.println("getMaxBinaryLiteralLength : " + dbmd.getMaxBinaryLiteralLength()); System.out.println("getMaxCatalogNameLength : " + dbmd.getMaxCatalogNameLength()); System.out.println("getMaxCharLiteralLength : " + dbmd.getMaxCharLiteralLength()); System.out.println("getMaxColumnNameLength : " + dbmd.getMaxColumnNameLength()); System.out.println("getMaxColumnsInGroupBy : " + dbmd.getMaxColumnsInGroupBy()); System.out.println("getMaxColumnsInIndex : " + dbmd.getMaxColumnsInIndex()); System.out.println("getMaxColumnsInOrderBy : " + dbmd.getMaxColumnsInOrderBy()); System.out.println("getMaxColumnsInSelect : " + dbmd.getMaxColumnsInSelect()); System.out.println("getMaxColumnsInTable : " + dbmd.getMaxColumnsInTable()); System.out.println("getMaxConnections : " + dbmd.getMaxConnections()); System.out.println("getMaxCursorNameLength : " + dbmd.getMaxCursorNameLength()); System.out.println("getMaxIndexLength : " + dbmd.getMaxIndexLength()); System.out.println("getMaxProcedureNameLength : " + dbmd.getMaxProcedureNameLength()); System.out.println("getMaxRowSize : " + dbmd.getMaxRowSize()); System.out.println("getMaxSchemaNameLength : " + dbmd.getMaxSchemaNameLength()); System.out.println("getMaxStatementLength : " + dbmd.getMaxStatementLength()); System.out.println("getMaxStatements : " + dbmd.getMaxStatements()); System.out.println("getMaxTableNameLength : " + dbmd.getMaxTableNameLength()); System.out.println("getMaxTablesInSelect : " + dbmd.getMaxTablesInSelect()); System.out.println("getMaxUserNameLength : " + dbmd.getMaxUserNameLength()); System.out.println("getNumericFunctions : " + dbmd.getNumericFunctions()); System.out.println("getProcedureTerm : " + dbmd.getProcedureTerm()); System.out.println("getResultSetHoldability : " + dbmd.getResultSetHoldability()); System.out.println("getRowIdLifetime : " + dbmd.getRowIdLifetime()); System.out.println("getSchemaTerm : " + dbmd.getSchemaTerm()); System.out.println("getSearchStringEscape : " + dbmd.getSearchStringEscape()); System.out.println("getSQLKeywords : " + dbmd.getSQLKeywords()); System.out.println("getSQLStateType : " + dbmd.getSQLStateType()); System.out.println("getStringFunctions : " + dbmd.getStringFunctions()); System.out.println("getSystemFunctions : " + dbmd.getSystemFunctions()); System.out.println("getSchemas : " + dbmd.getSchemas()); System.out.println("getTimeDateFunctions : " + dbmd.getTimeDateFunctions()); System.out.println("getURL : " + dbmd.getURL()); System.out.println("getUserName : " + dbmd.getUserName()); } }
以下は結果です。
※※※※※ METADATA ※※※※※ getCatalogSeparator : . getCatalogTerm : database getDatabaseProductName : MySQL getDatabaseProductVersion : 5.6.10 getDatabaseMajorVersion : 5 getDatabaseMinorVersion : 6 getDefaultTransactionIsolation : 2 getDriverMajorVersion : 5 getDriverMinorVersion : 1 getDriverName : MySQL Connector Java getDriverVersion : mysql-connector-java-5.1.36 ( Revision: 4fc1f969f740409a4e03750316df2c0e429f3dc8 ) getExtraNameCharacters : #@ getIdentifierQuoteString : ` getJDBCMajorVersion : 4 getJDBCMinorVersion : 0 getMaxBinaryLiteralLength : 16777208 getMaxCatalogNameLength : 32 getMaxCharLiteralLength : 16777208 getMaxColumnNameLength : 64 getMaxColumnsInGroupBy : 64 getMaxColumnsInIndex : 16 getMaxColumnsInOrderBy : 64 getMaxColumnsInSelect : 256 getMaxColumnsInTable : 512 getMaxConnections : 0 getMaxCursorNameLength : 64 getMaxIndexLength : 256 getMaxProcedureNameLength : 0 getMaxRowSize : 2147483639 getMaxSchemaNameLength : 0 getMaxStatementLength : 65531 getMaxStatements : 0 getMaxTableNameLength : 64 getMaxTablesInSelect : 256 getMaxUserNameLength : 16 getNumericFunctions : ABS,ACOS,ASIN,ATAN,ATAN2,BIT_COUNT,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MAX,MIN,MOD,PI,POW,POWER,RADIANS,RAND,ROUND,SIN,SQRT,TAN,TRUNCATE getProcedureTerm : PROCEDURE getResultSetHoldability : 1 getRowIdLifetime : ROWID_UNSUPPORTED getSchemaTerm : getSearchStringEscape : \ getSQLKeywords : ACCESSIBLE,ADD,ANALYZE,ASC,BEFORE,CASCADE,CHANGE,CONTINUE,DATABASE,DATABASES,DAY_HOUR,DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED,DESC,DISTINCTROW,DIV,DUAL,ELSEIF,ENCLOSED,ESCAPED,EXIT,EXPLAIN,FLOAT4,FLOAT8,FORCE,FULLTEXT,GENERATED,HIGH_PRIORITY,HOUR_MICROSECOND,HOUR_MINUTE,HOUR_SECOND,IF,IGNORE,INDEX,INFILE,INT1,INT2,INT3,INT4,INT8,IO_AFTER_GTIDS,IO_BEFORE_GTIDS,ITERATE,KEY,KEYS,KILL,LEAVE,LIMIT,LINEAR,LINES,LOAD,LOCK,LONG,LONGBLOB,LONGTEXT,LOOP,LOW_PRIORITY,MASTER_BIND,MASTER_SSL_VERIFY_SERVER_CERT,MAXVALUE,MEDIUMBLOB,MEDIUMINT,MEDIUMTEXT,MIDDLEINT,MINUTE_MICROSECOND,MINUTE_SECOND,NO_WRITE_TO_BINLOG,OPTIMIZE,OPTIMIZER_COSTS,OPTION,OPTIONALLY,OUTFILE,PARSE_GCOL_EXPR,PURGE,READ,READ_WRITE,REGEXP,RENAME,REPEAT,REPLACE,REQUIRE,RESIGNAL,RESTRICT,RLIKE,SCHEMA,SCHEMAS,SECOND_MICROSECOND,SEPARATOR,SHOW,SIGNAL,SPATIAL,SQL_BIG_RESULT,SQL_CALC_FOUND_ROWS,SQL_SMALL_RESULT,SSL,STARTING,STORED,STRAIGHT_JOIN,TERMINATED,TINYBLOB,TINYINT,TINYTEXT,UNDO,UNLOCK,UNSIGNED,USAGE,USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY,VARCHARACTER,VIRTUAL,WHILE,WRITE,XOR,YEAR_MONTH,ZEROFILL getSQLStateType : 2 getStringFunctions : ASCII,BIN,BIT_LENGTH,CHAR,CHARACTER_LENGTH,CHAR_LENGTH,CONCAT,CONCAT_WS,CONV,ELT,EXPORT_SET,FIELD,FIND_IN_SET,HEX,INSERT,INSTR,LCASE,LEFT,LENGTH,LOAD_FILE,LOCATE,LOCATE,LOWER,LPAD,LTRIM,MAKE_SET,MATCH,MID,OCT,OCTET_LENGTH,ORD,POSITION,QUOTE,REPEAT,REPLACE,REVERSE,RIGHT,RPAD,RTRIM,SOUNDEX,SPACE,STRCMP,SUBSTRING,SUBSTRING,SUBSTRING,SUBSTRING,SUBSTRING_INDEX,TRIM,UCASE,UPPER getSystemFunctions : DATABASE,USER,SYSTEM_USER,SESSION_USER,PASSWORD,ENCRYPT,LAST_INSERT_ID,VERSION getSchemas : com.mysql.jdbc.JDBC4ResultSet@60XXXXX getTimeDateFunctions : DAYOFWEEK,WEEKDAY,DAYOFMONTH,DAYOFYEAR,MONTH,DAYNAME,MONTHNAME,QUARTER,WEEK,YEAR,HOUR,MINUTE,SECOND,PERIOD_ADD,PERIOD_DIFF,TO_DAYS,FROM_DAYS,DATE_FORMAT,TIME_FORMAT,CURDATE,CURRENT_DATE,CURTIME,CURRENT_TIME,NOW,SYSDATE,CURRENT_TIMESTAMP,UNIX_TIMESTAMP,FROM_UNIXTIME,SEC_TO_TIME,TIME_TO_SEC getURL : jdbc:mysql://cm1-cluster.cluster-XXXXXXXXXXXX.us-west-2.rds.amazonaws.com:3306/?user=XXXX&password=XXXX getUserName : admin@XXX.XXX.XXX.XXX
Auroraの各種サポート状況を取得する
import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; import java.sql.ResultSet; public class AuroraSupports { public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://cm1-cluster.cluster-XXXX.us-west-2.rds.amazonaws.com:3306/?user=XXXX&password=XXXX"; Connection conn = DriverManager.getConnection(url); DatabaseMetaData dbmd = conn.getMetaData(); System.out.println("※※※※※ SUPPORTS ※※※※※"); System.out.println("supportsAlterTableWithAddColumn : " + dbmd.supportsAlterTableWithAddColumn()); System.out.println("supportsAlterTableWithDropColumn : " + dbmd.supportsAlterTableWithDropColumn()); System.out.println("supportsANSI92EntryLevelSQL : " + dbmd.supportsANSI92EntryLevelSQL()); System.out.println("supportsANSI92FullSQL : " + dbmd.supportsANSI92FullSQL()); System.out.println("supportsANSI92IntermediateSQL : " + dbmd.supportsANSI92IntermediateSQL()); System.out.println("supportsBatchUpdates : " + dbmd.supportsBatchUpdates()); System.out.println("supportsCatalogsInDataManipulation : " + dbmd.supportsCatalogsInDataManipulation()); System.out.println("supportsCatalogsInIndexDefinitions : " + dbmd.supportsCatalogsInIndexDefinitions()); System.out.println("supportsCatalogsInPrivilegeDefinitions : " + dbmd.supportsCatalogsInPrivilegeDefinitions()); System.out.println("supportsCatalogsInProcedureCalls : " + dbmd.supportsCatalogsInProcedureCalls()); System.out.println("supportsCatalogsInTableDefinitions : " + dbmd.supportsCatalogsInTableDefinitions()); System.out.println("supportsColumnAliasing : " + dbmd.supportsColumnAliasing()); System.out.println("supportsConvert : " + dbmd.supportsConvert()); System.out.println("supportsCoreSQLGrammar : " + dbmd.supportsCoreSQLGrammar()); System.out.println("supportsCorrelatedSubqueries : " + dbmd.supportsCorrelatedSubqueries()); System.out.println("supportsDataDefinitionAndDataManipulationTransactions : " + dbmd.supportsDataDefinitionAndDataManipulationTransactions()); System.out.println("supportsDataManipulationTransactionsOnly : " + dbmd.supportsDataManipulationTransactionsOnly()); System.out.println("supportsDifferentTableCorrelationNames : " + dbmd.supportsDifferentTableCorrelationNames()); System.out.println("supportsExpressionsInOrderBy : " + dbmd.supportsExpressionsInOrderBy()); System.out.println("supportsExtendedSQLGrammar : " + dbmd.supportsExtendedSQLGrammar()); System.out.println("supportsFullOuterJoins : " + dbmd.supportsFullOuterJoins()); System.out.println("supportsGetGeneratedKeys : " + dbmd.supportsGetGeneratedKeys()); System.out.println("supportsGroupBy : " + dbmd.supportsGroupBy()); System.out.println("supportsGroupByBeyondSelect : " + dbmd.supportsGroupByBeyondSelect()); System.out.println("supportsGroupByUnrelated : " + dbmd.supportsGroupByUnrelated()); System.out.println("supportsIntegrityEnhancementFacility : " + dbmd.supportsIntegrityEnhancementFacility()); System.out.println("supportsLikeEscapeClause : " + dbmd.supportsLikeEscapeClause()); System.out.println("supportsLimitedOuterJoins : " + dbmd.supportsLimitedOuterJoins()); System.out.println("supportsMinimumSQLGrammar : " + dbmd.supportsMinimumSQLGrammar()); System.out.println("supportsMixedCaseIdentifiers : " + dbmd.supportsMixedCaseIdentifiers()); System.out.println("supportsMixedCaseQuotedIdentifiers : " + dbmd.supportsMixedCaseQuotedIdentifiers()); System.out.println("supportsMultipleOpenResults : " + dbmd.supportsMultipleOpenResults()); System.out.println("supportsMultipleResultSets : " + dbmd.supportsMultipleResultSets()); System.out.println("supportsMultipleTransactions : " + dbmd.supportsMultipleTransactions()); System.out.println("supportsNamedParameters : " + dbmd.supportsNamedParameters()); System.out.println("supportsNonNullableColumns : " + dbmd.supportsNonNullableColumns()); System.out.println("supportsOpenCursorsAcrossCommit : " + dbmd.supportsOpenCursorsAcrossCommit()); System.out.println("supportsOpenCursorsAcrossRollback : " + dbmd.supportsOpenCursorsAcrossRollback()); System.out.println("supportsOpenStatementsAcrossCommit : " + dbmd.supportsOpenStatementsAcrossCommit()); System.out.println("supportsOpenStatementsAcrossRollback : " + dbmd.supportsOpenStatementsAcrossRollback()); System.out.println("supportsOrderByUnrelated : " + dbmd.supportsOrderByUnrelated()); System.out.println("supportsOuterJoins : " + dbmd.supportsOuterJoins()); System.out.println("supportsPositionedDelete : " + dbmd.supportsPositionedDelete()); System.out.println("supportsPositionedUpdate : " + dbmd.supportsPositionedUpdate()); System.out.println("supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT) : " + dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT)); System.out.println("supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT) : " + dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT)); System.out.println("supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY) : " + dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY)); System.out.println("supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE) : " + dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)); System.out.println("supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE) : " + dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE)); System.out.println("supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE) : " + dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)); System.out.println("supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) : " + dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)); System.out.println("supportsSavepoints : " + dbmd.supportsSavepoints()); System.out.println("supportsSchemasInDataManipulation : " + dbmd.supportsSchemasInDataManipulation()); System.out.println("supportsSchemasInIndexDefinitions : " + dbmd.supportsSchemasInIndexDefinitions()); System.out.println("supportsSchemasInPrivilegeDefinitions : " + dbmd.supportsSchemasInPrivilegeDefinitions()); System.out.println("supportsSchemasInProcedureCalls : " + dbmd.supportsSchemasInProcedureCalls()); System.out.println("supportsSchemasInTableDefinitions : " + dbmd.supportsSchemasInTableDefinitions()); System.out.println("supportsSelectForUpdate : " + dbmd.supportsSelectForUpdate()); System.out.println("supportsStatementPooling : " + dbmd.supportsStatementPooling()); System.out.println("supportsStoredFunctionsUsingCallSyntax : " + dbmd.supportsStoredFunctionsUsingCallSyntax()); System.out.println("supportsStoredProcedures : " + dbmd.supportsStoredProcedures()); System.out.println("supportsSubqueriesInComparisons : " + dbmd.supportsSubqueriesInComparisons()); System.out.println("supportsSubqueriesInExists : " + dbmd.supportsSubqueriesInExists()); System.out.println("supportsSubqueriesInIns : " + dbmd.supportsSubqueriesInIns()); System.out.println("supportsSubqueriesInQuantifieds : " + dbmd.supportsSubqueriesInQuantifieds()); System.out.println("supportsTableCorrelationNames : " + dbmd.supportsTableCorrelationNames()); System.out.println("supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE) : " + dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE)); System.out.println("supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED) : " + dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED)); System.out.println("supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED) : " + dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED)); System.out.println("supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ) : " + dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ)); System.out.println("supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE) : " + dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE)); System.out.println("supportsTransactions : " + dbmd.supportsTransactions()); System.out.println("supportsUnion : " + dbmd.supportsUnion()); System.out.println("supportsUnionAll : " + dbmd.supportsUnionAll()); } }
以下は結果です。
※※※※※ SUPPORTS ※※※※※ supportsAlterTableWithAddColumn : true supportsAlterTableWithDropColumn : true supportsANSI92EntryLevelSQL : true supportsANSI92FullSQL : false supportsANSI92IntermediateSQL : false supportsBatchUpdates : true supportsCatalogsInDataManipulation : true supportsCatalogsInIndexDefinitions : true supportsCatalogsInPrivilegeDefinitions : true supportsCatalogsInProcedureCalls : true supportsCatalogsInTableDefinitions : true supportsColumnAliasing : true supportsConvert : false supportsCoreSQLGrammar : true supportsCorrelatedSubqueries : true supportsDataDefinitionAndDataManipulationTransactions : false supportsDataManipulationTransactionsOnly : false supportsDifferentTableCorrelationNames : true supportsExpressionsInOrderBy : true supportsExtendedSQLGrammar : false supportsFullOuterJoins : false supportsGetGeneratedKeys : true supportsGroupBy : true supportsGroupByBeyondSelect : true supportsGroupByUnrelated : true supportsIntegrityEnhancementFacility : false supportsLikeEscapeClause : true supportsLimitedOuterJoins : true supportsMinimumSQLGrammar : true supportsMixedCaseIdentifiers : true supportsMixedCaseQuotedIdentifiers : true supportsMultipleOpenResults : true supportsMultipleResultSets : true supportsMultipleTransactions : true supportsNamedParameters : false supportsNonNullableColumns : true supportsOpenCursorsAcrossCommit : false supportsOpenCursorsAcrossRollback : false supportsOpenStatementsAcrossCommit : false supportsOpenStatementsAcrossRollback : false supportsOrderByUnrelated : false supportsOuterJoins : true supportsPositionedDelete : false supportsPositionedUpdate : false supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT) : true supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT) : false supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY) : false supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE) : true supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE) : false supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE) : true supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) : true supportsSavepoints : true supportsSchemasInDataManipulation : false supportsSchemasInIndexDefinitions : false supportsSchemasInPrivilegeDefinitions : false supportsSchemasInProcedureCalls : false supportsSchemasInTableDefinitions : false supportsSelectForUpdate : true supportsStatementPooling : false supportsStoredFunctionsUsingCallSyntax : true supportsStoredProcedures : true supportsSubqueriesInComparisons : true supportsSubqueriesInExists : true supportsSubqueriesInIns : true supportsSubqueriesInQuantifieds : true supportsTableCorrelationNames : true supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE) : false supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED) : true supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED) : true supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ) : true supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE) : true supportsTransactions : true supportsUnion : true supportsUnionAll : true
まとめ
Amazon Auroraは、ガッツリ本番投入できるレベルの各種サポート対応したデータベースですっ!!